#!/usr/bin/env python

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'search_admin_form.ui'
#
# Created: Thu Apr 30 02:36:12 2009
#      by: The PyQt User Interface Compiler (pyuic) 3.17.6
#
# WARNING! All changes made in this file will be lost!


from qt import *
import anydbm
from manage_form import *

class search_admin_form(QDialog):
    def __init__(self,parent = None,name = None,modal = 0,fl = 0):
        QDialog.__init__(self,parent,name,modal,fl)

        if not name:
            self.setName("search_admin_form")



        self.groupBox4 = QGroupBox(self,"groupBox4")
        self.groupBox4.setGeometry(QRect(10,10,361,70))

        self.lineEdit3 = QLineEdit(self.groupBox4,"lineEdit3")
        self.lineEdit3.setGeometry(QRect(130,30,210,22))

        self.textLabel2 = QLabel(self.groupBox4,"textLabel2")
        self.textLabel2.setGeometry(QRect(20,30,99,20))

        self.search_btn = QPushButton(self,"search_btn")
        self.search_btn.setGeometry(QRect(270,90,103,27))

        self.cancel_search_btn = QPushButton(self,"cancel_search_btn")
        self.cancel_search_btn.setGeometry(QRect(160,90,103,27))

        self.languageChange()

        self.resize(QSize(380,129).expandedTo(self.minimumSizeHint()))
        self.clearWState(Qt.WState_Polished)

        self.connect(self.search_btn,SIGNAL("clicked()"),self.search_btn_clicked)
        self.connect(self.cancel_search_btn,SIGNAL("clicked()"),self.cancel_search_btn_clicked)


    def languageChange(self):
        self.setCaption(self.__tr("Search Admin"))
        self.groupBox4.setTitle(self.__tr("Search Admin"))
        self.textLabel2.setText(self.__tr("Adminstrator"))
        self.search_btn.setText(self.__tr("&Search"))
        self.search_btn.setAccel(QKeySequence(self.__tr("Alt+S")))
        self.cancel_search_btn.setText(self.__tr("&Cancel"))
        self.cancel_search_btn.setAccel(QKeySequence(self.__tr("Alt+C")))


    def search_btn_clicked(self):
        """
        search_btn_clicked(self):
            this function search an administrator on the database
            if found message box will pop up containing the password
            of that administrator
        """
        admin_db = anydbm.open('Admin_Accounts','r')
        admin_account = str(self.lineEdit3.text())
        if admin_account == '':
            Message = "You must enter available admin to search"
            QMessageBox.critical(self,"Warning!",Message,QMessageBox.Ok)
        elif admin_db.has_key(admin_account):
            Message = "%s password is %s" %(admin_account,admin_db[admin_account])
            QMessageBox.information(self,"Search!",Message,QMessageBox.Ok)
        else:
            Message = 'administrator you searched not exist !'
            QMessageBox.critical(self,"Warning!",Message,QMessageBox.Ok)

    def cancel_search_btn_clicked(self):
        self.hide()

    def __tr(self,s,c = None):
        return qApp.translate("search_admin_form",s,c)
